<?php
declare(strict_types=1);
 

namespace App\Marketing\Mapper;

use App\Marketing\Model\MarketingLotto;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 彩票列表Mapper类
 */
class MarketingLottoMapper extends AbstractMapper
{
    /**
     * @var MarketingLotto
     */
    public $model;

    public function assignModel()
    {
        $this->model = MarketingLotto::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // 主键
        if (isset($params['id']) && filled($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 
        if (isset($params['created_at']) && filled($params['created_at']) && is_array($params['created_at']) && count($params['created_at']) == 2) {
            $query->whereBetween(
                'created_at',
                [ $params['created_at'][0], $params['created_at'][1] ]
            );
        }

        // 
        if (isset($params['updated_at']) && filled($params['updated_at']) && is_array($params['updated_at']) && count($params['updated_at']) == 2) {
            $query->whereBetween(
                'updated_at',
                [ $params['updated_at'][0], $params['updated_at'][1] ]
            );
        }

        // 删除时间
        if (isset($params['deleted_at']) && filled($params['deleted_at']) && is_array($params['deleted_at']) && count($params['deleted_at']) == 2) {
            $query->whereBetween(
                'deleted_at',
                [ $params['deleted_at'][0], $params['deleted_at'][1] ]
            );
        }

        // 创建者
        if (isset($params['created_by']) && filled($params['created_by'])) {
            $query->where('created_by', '=', $params['created_by']);
        }

        // 更新者
        if (isset($params['updated_by']) && filled($params['updated_by'])) {
            $query->where('updated_by', '=', $params['updated_by']);
        }

        // code
        if (isset($params['code']) && filled($params['code'])) {
            $query->where('code', '=', $params['code']);
        }

        // 号码组数
        if (isset($params['groups']) && filled($params['groups'])) {
            $query->where('groups', '=', $params['groups']);
        }

        // 期数
        if (isset($params['periods']) && filled($params['periods'])) {
            $query->where('periods', '=', $params['periods']);
        }

        // 中奖号码
        if (isset($params['no']) && filled($params['no'])) {
            $query->where('no', '=', $params['no']);
        }

        // 奖池
        if (isset($params['pool']) && filled($params['pool'])) {
            $query->where('pool', '=', $params['pool']);
        }

        // 1分2时3天
        if (isset($params['open_type']) && filled($params['open_type'])) {
            $query->where('open_type', '=', $params['open_type']);
        }

        // 开奖时间
        if (isset($params['open_time']) && filled($params['open_time'])) {
            $query->where('open_time', '=', $params['open_time']);
        }

        // 满人开
        if (isset($params['people_num']) && filled($params['people_num'])) {
            $query->where('people_num', '=', $params['people_num']);
        }

        // 
        if (isset($params['name']) && filled($params['name'])) {
            $query->where('name', '=', $params['name']);
        }

        // 
        if (isset($params['content']) && filled($params['content'])) {
            $query->where('content', '=', $params['content']);
        }

        // 
        if (isset($params['config']) && filled($params['config'])) {
            $query->where('config', '=', $params['config']);
        }

        return $query;
    }
}